﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using VietThuongLMS.Services;
//Author: Kha
namespace VietThuongLMS.ViewModels
{
    public class BaoCaoViewModel
    {
        public int SoLuongLopHoc { get; set; }
        public int SoLuongGiaoVien { get; set; }
        public ChiNhanh CN { get; set; }
        public BaoCaoViewModel ()
        {
            List2 = new List<PhanCongMoRongModel>();
            List3 = new List<HocVien_LopMoRongModel>();
        }

        public List<PhanCongMoRongModel> List2 { get; set; }
        public List<HocVien_LopMoRongModel> List3 { get; set; }
        public BaoCaoViewModel(List<PhanCongMoRongModel> lista, List<HocVien_LopMoRongModel> listb)
        {
            List2 = lista;
            List3 = listb;
        }
        public string TongChi { get; set; }
        public string TongThu { get; set; }
        public string TongChiThem { get; set; }
        public string TongThuThem { get; set; }
        public string LoiNhuan { get; set; }
        public void TinhTongChi()
        {
            double sum = 0;
            for (int i = 0; i < List2.Count; i++)
            {
                sum = sum + List2[i].TienCong;
            }
            TongChi = sum.ToString();
        }
        public void TinhTongThu()
        {
            double sum = 0;
            for (int i = 0; i < List3.Count; i++)
            {
                sum = sum + double.Parse(List3[i].HV_L.TienDaDong);
            }
            TongThu = sum.ToString();
        }
        public void TinhChiThem(int id, int m, int y)
        {
            List<DoanhThu> list = DoanhThuService.GetDoanhThuByCNId(id, m, y);
            double sum = 0;
            if (list != null)
            {
                foreach (DoanhThu dt in list)
                {
                    sum += dt.TienChi.Value;
                }
                TongChiThem = sum.ToString();
            }
            else
                TongChiThem = "0";
        }
        public void TinhThuThem(int id, int m, int y)
        {
            List<DoanhThu> list = DoanhThuService.GetDoanhThuByCNId(id, m, y);
            double sum = 0;
            if (list != null)
            {
                foreach (DoanhThu dt in list)
                {
                    sum += dt.TienThu.Value;
                }
                TongThuThem = sum.ToString();
            }
            else
                TongThuThem = "0";
        }
        public void TinhLoiNhuan()
        {
            LoiNhuan = (double.Parse(TongThu) - double.Parse(TongChi) +
                        double.Parse(TongThuThem) - double.Parse(TongChiThem)).ToString();
        }
    }

    public class BaoCaoTatCaViewModel
    {
        public List<BaoCaoViewModel> List { get; set; }
        public string TongThu { get; set; }
        public string TongChi {get; set;}
        public string TongLoiNhuan { get; set; }
        public BaoCaoTatCaViewModel()
        {
            List = new List<BaoCaoViewModel>();
        }
        public void ThemBaoCao(BaoCaoViewModel bcvm)
        {
            List.Add(bcvm);
        }
        public void TinhTongChi()
        {
            double sum = 0;
            foreach (BaoCaoViewModel bcvm in List)
            {
                sum = sum + double.Parse(bcvm.TongChi);

                DoanhThu dt = DoanhThuService.GetDoanhThuById(bcvm.CN.ID);
                if (dt != null && dt.TienChi > 0)
                    sum += dt.TienChi.Value;
            }
            TongChi = sum.ToString();
        }
        public void TinhTongThu()
        {
            double sum = 0;
            foreach (BaoCaoViewModel bcvm in List)
            {
                sum = sum + double.Parse(bcvm.TongThu);

                DoanhThu dt = DoanhThuService.GetDoanhThuById(bcvm.CN.ID);
                if (dt != null && dt.TienThu > 0)
                    sum += dt.TienThu.Value;
            }
            TongThu = sum.ToString();
        }
        public void TinhTongLoiNhuan()
        {
            double sum = 0;
            foreach (BaoCaoViewModel bcvm in List)
            {
                sum = sum + double.Parse(bcvm.LoiNhuan);
            }
            TongLoiNhuan = sum.ToString();
        }
    }



}